import {defineConfig} from 'vite'
import vue from '@vitejs/plugin-vue'
import * as path from 'path';
import viteCompression from 'vite-plugin-compression'

export default defineConfig({
    resolve: {
        //设置别名
        alias: {
            '@': path.resolve(__dirname, 'src')
        }
    },
    css: {
        preprocessorOptions: {
            scss: {
                // additionalData: `@use "@/assets/styles/element/index.scss" as *;`,
            },
        },
    },
    plugins: [
        vue(),
        viteCompression({
            verbose: true,
            disable: false,
            threshold: 10240,
            algorithm: 'gzip',
            ext: '.gz',
        })],
    //打包配置
    build: {
        chunkSizeWarningLimit: 1500,
        rollupOptions: {
            output: {
                chunkFileNames: 'static/ts/[name]-[hash].ts',
                entryFileNames: 'static/ts/[name]-[hash].ts',
                assetFileNames: 'static/[ext]/[name]-[hash].[ext]',
                manualChunks(id) { //静态资源分拆打包
                    if (id.includes('node_modules')) {
                        return id.toString().split('node_modules/')[1].split('/')[0].toString();
                    }
                }
            }
        }
    },
    server: {
        port: 8081, //启动端口
        // host: '127.0.0.1',
        open: true
        // 设置 https 代理
        // proxy: {
        //   '/api': {
        //     target: '',
        //     changeOrigin: true,
        //     rewrite: (path: string) => path.replace(/^\/api/, '')
        //   }
        // }
    }
})
